import {Component} from '@angular/core';
import {AlertController, LoadingController, NavController, NavParams, Platform, ToastController} from 'ionic-angular';
import {BasePage} from "../BasePage";
import {Log} from "../../framework/utils/Log";
import {SystemService} from "../service/SystemService";
import { ThrowStmt } from '@angular/compiler';

@Component({
    selector: 'page-examineApprove',
    templateUrl: 'examineApprove.html',
    providers: [SystemService]
})
export class ExamineApprovePage extends BasePage {
    private static TAG: string = 'ExamineApprovePage';
    public tabs: Array<object> = [
        {
            name: '申请信息'
        },
        {
            name: '流程'
        },
        {
            name: '审批'
        }
    ];
    public title = '待办审批';
    infoBool: boolean = false;
    flowBool: boolean = false;
    approveBool: boolean = false;
    selectId: any = 0;
    detailItem:any;
    private detailInfo: any;
    private yaosuList:any;
    private sqbmBH:any;
    private flowImgUrl:any;
    private hqList:any=[];
    applyFee:string;
    danJuType:string;
    sxType:string;
    constructor(public navCtrl: NavController,
                public platform: Platform,
                public navParams: NavParams,
                public sys: SystemService,
                public loadingCtrl: LoadingController,
                public toastCtrl: ToastController,
                public alertCtrl: AlertController) {
        super(platform, loadingCtrl, toastCtrl, alertCtrl);
        this.detailItem = navParams.data.data;
        this.sxType = this.navParams.data.type;
        Log.printObj(ExamineApprovePage.TAG, 'data==', this.detailItem);
    }

    async ngOnInit() {
        this.showLoading(true,'加载中');
    }

    ionViewDidEnter() {
        let _id:any = document.getElementsByClassName('tab');
        if(this.sxType =='2'){
            this.tabs= [
                {
                    name: '申请信息'
                },
                {
                    name: '流程'
                }
            ];
            this.title = '报销调看';
        }
        this.getCheckDetail(this.detailItem);
    }

    async getCheckDetail(_d) {
        let data: any = {
            BianHao: _d.DanJuBH,
            LiuChengId: _d.LiuChengId,
            RenWuID: _d.RenWuID,
            DangQianJD: _d.DangQianJD
        };
      await this.sys.getCheckDetail(data).subscribe((res: any) => {
            Log.printObj(ExamineApprovePage.TAG, 'printObj==', res);
            if (res.msgCode == '1') {
                this.detailInfo = res;
                this.flowImgUrl=res.DanJuXX.LiuChengTuLJ;
                this.applyFee = res.DanJuXX.ShenQingJE;
                this.danJuType = res.DanJuXX.BaoXiaoDLX;
                this.yaosuList=res.YaoSuXX;
                this.sqbmBH = res.DanJuXX.ShenQingBMBH;
                this.hqList = res.DanJuXX.hqList;
                this.tabName('申请信息', 0);
                this.infoBool =true;

                this.showLoading(false,'');

            } else {
                this.showError('数据请求失败');
            }

        }, error => {
            this.showError('数据请求失败');
        })
    }



    tabName(name, id) {
        this.allTabsBool();
        let tabId: any = document.getElementById('extabLine_' + id).style;
        let _selectId: any = document.getElementById('extabLine_' + this.selectId).style;
        let tabTxtId: any = document.getElementById('dbtabName' + id).style;
        let setabTxtId: any = document.getElementById('dbtabName' + this.selectId).style;
        setabTxtId.color = "#666666";
        _selectId.backgroundColor = 'rgba(0,0,0,0)';
        switch (name) {
            case '申请信息':
                this.selectId = 0;
                this.infoBool = true;
                break;
            case '流程':
                this.selectId = 1;
                this.flowBool = true;
                break;
            case '审批':
                this.selectId = 2;
                this.approveBool = true;
                break;
        }
        tabId.backgroundColor = '#3189fb';
        tabTxtId.color = "#1c70bf";
    }

    allTabsBool() {
        this.infoBool = false;
        this.flowBool = false;
        this.approveBool = false;

    }
}
